package ynu.edu.online_course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ynu.edu.online_course.entity.Course;
import ynu.edu.online_course.service.CourseService;

@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping
    public ResponseEntity<?> getAllCourses() {
        return ResponseEntity.ok(courseService.getAllCourses());
    }

    @PostMapping
    public ResponseEntity<?> addCourse(@RequestBody Course course,@RequestBody Long UserId) {
        courseService.addCourse(course, UserId);
        return ResponseEntity.ok("课程已成功添加");
    }

    @PutMapping("/{id}")
    public ResponseEntity<?> updateCourse(@RequestBody Course course,@RequestBody Long UserId) {
        courseService.updateCourse(course, UserId);
        return ResponseEntity.ok("课程信息已修改");
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> deleteCourse(@PathVariable Long id,@RequestBody Long UserId ) {
        courseService.deleteCourse(id, UserId);
        return ResponseEntity.ok("课程已成功删除");
    }
}

